package www.study.com;

import java.util.Map;

//整数转罗马数字 https://leetcode.cn/problems/integer-to-roman/
public class code12 {
    public static void main(String[] args) {

    }

    class Solution {
        public String intToRoman(int num) {
            int[] nums = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
            String[] vals = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
            StringBuilder sb = new StringBuilder();
            for(int i = nums.length - 1 ; i > -1 ; i--){
                while(num >= nums[i]){
                    sb.append(vals[i]);

                    num -= nums[i];
                }
            }
            return sb.toString();
            // Map<Integer, String> numToChar = new TreeMap<>(new Comparator<Integer>(){
            //     public int compare(Integer o1, Integer o2){
            //         return o2 - o1;
            //     }
            // });
            // initMap(numToChar);
            // StringBuilder sb = new StringBuilder();
            // for(Map.Entry<Integer, String> entry : numToChar.entrySet()){
            //     int k = entry.getKey();
            //     String v = entry.getValue();
            //     int number = num / k;
            //     num %= k;
            //     for(int i = 0 ; i < number ; i++){
            //         sb.append(v);
            //     }
            //     if(num == 0) break;
            // }
            // return sb.toString();
        }
        public void initMap(Map<Integer, String> numToChar){
            numToChar.put(1,"I");
            numToChar.put(5,"V");
            numToChar.put(10,"X");
            numToChar.put(50,"L");
            numToChar.put(100,"C");
            numToChar.put(500,"D");
            numToChar.put(1000,"M");
            numToChar.put(4,"IV");
            numToChar.put(9,"IX");
            numToChar.put(40,"XL");
            numToChar.put(90,"XC");
            numToChar.put(400,"CD");
            numToChar.put(900,"CM");
        }
    }
}
